<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="虚拟仓名称" prop="virtualWarehouseName">
        <el-input
          v-model="queryParams.virtualWarehouseName"
          placeholder="请输入虚拟仓名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色规格" prop="colorSpecification">
        <el-input
          v-model="queryParams.colorSpecification"
          placeholder="请输入颜色规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品编码" prop="sku">
        <el-input
          v-model="queryParams.sku"
          placeholder="请输入商品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="款式编码" prop="spu">
        <el-input
          v-model="queryParams.spu"
          placeholder="请输入款式编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>
      <!-- </el-col> -->

      <div v-show="isOpen">
        <el-form-item label="数量" prop="quantity">
          <el-input
            v-model="queryParams.quantity"
            placeholder="请输入数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="订单占有数" prop="orderPossession">
          <el-input
            v-model="queryParams.orderPossession"
            placeholder="请输入订单占有数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="仓库待发数" prop="warehousePending">
          <el-input
            v-model="queryParams.warehousePending"
            placeholder="请输入仓库待发数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="虚拟库存数" prop="virtualStock">
          <el-input
            v-model="queryParams.virtualStock"
            placeholder="请输入虚拟库存数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="虚拟仓可用数" prop="virtualWarehouseAvailable">
          <el-input
            v-model="queryParams.virtualWarehouseAvailable"
            placeholder="请输入虚拟仓可用数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="虚拟仓可配货数" prop="virtualWarehouseAllocable">
          <el-input
            v-model="queryParams.virtualWarehouseAllocable"
            placeholder="请输入虚拟仓可配货数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="实际库存数" prop="actualStock">
          <el-input
            v-model="queryParams.actualStock"
            placeholder="请输入实际库存数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="公有可用数" prop="publicAvailableStock">
          <el-input
            v-model="queryParams.publicAvailableStock"
            placeholder="请输入公有可用数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item
          label="公有可用数不包含虚拟库存"
          prop="publicAvailableStockExcludingVirtual"
        >
          <el-input
            v-model="queryParams.publicAvailableStockExcludingVirtual"
            placeholder="请输入公有可用数不包含虚拟库存"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="调拨在途数" prop="transferInTransit">
          <el-input
            v-model="queryParams.transferInTransit"
            placeholder="请输入调拨在途数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="进货仓库存" prop="purchaseWarehouseStock">
          <el-input
            v-model="queryParams.purchaseWarehouseStock"
            placeholder="请输入进货仓库存"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="7天发货量" prop="sevenDayShipments">
          <el-input
            v-model="queryParams.sevenDayShipments"
            placeholder="请输入7天发货量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="15天发货量" prop="fifteenDayShipments">
          <el-input
            v-model="queryParams.fifteenDayShipments"
            placeholder="请输入15天发货量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="30天发货量" prop="thirtyDayShipments">
          <el-input
            v-model="queryParams.thirtyDayShipments"
            placeholder="请输入30天发货量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="7天退货量" prop="sevenDayReturns">
          <el-input
            v-model="queryParams.sevenDayReturns"
            placeholder="请输入7天退货量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="15天退货量" prop="fifteenDayReturns">
          <el-input
            v-model="queryParams.fifteenDayReturns"
            placeholder="请输入15天退货量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="30天退货量" prop="thirtyDayReturns">
          <el-input
            v-model="queryParams.thirtyDayReturns"
            placeholder="请输入30天退货量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="库存同步数" prop="inventorySync">
          <el-input
            v-model="queryParams.inventorySync"
            placeholder="请输入库存同步数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="成本" prop="cost">
          <el-input
            v-model="queryParams.cost"
            placeholder="请输入成本"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="虚拟仓库存金额" prop="virtualWarehouseStockValue">
          <el-input
            v-model="queryParams.virtualWarehouseStockValue"
            placeholder="请输入虚拟仓库存金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item
          label="虚拟仓采购在途"
          prop="virtualWarehouseProcurementInTransit"
        >
          <el-input
            v-model="queryParams.virtualWarehouseProcurementInTransit"
            placeholder="请输入虚拟仓采购在途"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="安全库存下限" prop="minSafeStock">
          <el-input
            v-model="queryParams.minSafeStock"
            placeholder="请输入安全库存下限"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="安全库存上限" prop="maxSafeStock">
          <el-input
            v-model="queryParams.maxSafeStock"
            placeholder="请输入安全库存上限"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="安全库存天数下限" prop="minSafeDays">
          <el-input
            v-model="queryParams.minSafeDays"
            placeholder="请输入安全库存天数下限"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="安全库存天数上限" prop="maxSafeDays">
          <el-input
            v-model="queryParams.maxSafeDays"
            placeholder="请输入安全库存天数上限"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:origvirtualinventory:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:origvirtualinventory:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:origvirtualinventory:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:origvirtualinventory:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-upload
          ref="daoru"
          :action="Upload.url"
          :headers="Upload.headers"
          :limit="limit"
          :on-exceed="handleExceed"
          :on-success="handlePictureSuccessPic"
          :before-upload="beforeAvatarUpload"
          :on-preview="handlePictureCardPreview"
          :file-list="fileLi"
          :on-change="changeFile1"
        >
          <el-button size="mini">批量导入</el-button>
          <!-- <i class="el-icon-plus"></i> -->
        </el-upload>
        <!-- <el-button size="mini" plain icon="el-icon-upload" @click="daoru"
          >导入</el-button
        > -->
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="origvirtualinventoryList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column width="120" label="自增加ID" align="center" prop="id" />
      <el-table-column
        width="120"
        label="虚拟仓名称"
        align="center"
        prop="virtualWarehouseName"
      />
      <el-table-column width="120" label="图" align="center" prop="imageUrl">
        <template slot-scope="scope">
          <image-preview-full
            :src="scope.row.imageUrl"
            :width="30"
            :height="30"
          />
        </template>
      </el-table-column>
      <el-table-column
        width="120"
        label="商品名称"
        align="center"
        prop="productName"
      />
      <el-table-column
        width="120"
        label="颜色规格"
        align="center"
        prop="colorSpecification"
      />
      <el-table-column width="120" label="商品编码" align="center" prop="sku" />
      <el-table-column width="120" label="款式编码" align="center" prop="spu" />
      <el-table-column width="120" label="状态" align="center" prop="status" />
      <el-table-column
        width="120"
        label="数量"
        align="center"
        prop="quantity"
      />
      <el-table-column
        width="120"
        label="订单占有数"
        align="center"
        prop="orderPossession"
      />
      <el-table-column
        width="120"
        label="仓库待发数"
        align="center"
        prop="warehousePending"
      />
      <el-table-column
        width="120"
        label="虚拟库存数"
        align="center"
        prop="virtualStock"
      />
      <el-table-column
        width="120"
        label="虚拟仓可用数"
        align="center"
        prop="virtualWarehouseAvailable"
      />
      <el-table-column
        width="120"
        label="虚拟仓可配货数"
        align="center"
        prop="virtualWarehouseAllocable"
      />
      <el-table-column
        width="120"
        label="实际库存数"
        align="center"
        prop="actualStock"
      />
      <el-table-column
        width="120"
        label="公有可用数"
        align="center"
        prop="publicAvailableStock"
      />
      <el-table-column
        width="120"
        label="公有可用数不包含虚拟库存"
        align="center"
        prop="publicAvailableStockExcludingVirtual"
      />
      <el-table-column
        width="120"
        label="调拨在途数"
        align="center"
        prop="transferInTransit"
      />
      <el-table-column
        width="120"
        label="进货仓库存"
        align="center"
        prop="purchaseWarehouseStock"
      />
      <el-table-column
        width="120"
        label="7天发货量"
        align="center"
        prop="sevenDayShipments"
      />
      <el-table-column
        width="120"
        label="15天发货量"
        align="center"
        prop="fifteenDayShipments"
      />
      <el-table-column
        width="120"
        label="30天发货量"
        align="center"
        prop="thirtyDayShipments"
      />
      <el-table-column
        width="120"
        label="7天退货量"
        align="center"
        prop="sevenDayReturns"
      />
      <el-table-column
        width="120"
        label="15天退货量"
        align="center"
        prop="fifteenDayReturns"
      />
      <el-table-column
        width="120"
        label="30天退货量"
        align="center"
        prop="thirtyDayReturns"
      />
      <el-table-column
        width="120"
        label="库存同步数"
        align="center"
        prop="inventorySync"
      />
      <el-table-column width="120" label="成本" align="center" prop="cost" />
      <el-table-column
        width="120"
        label="虚拟仓库存金额"
        align="center"
        prop="virtualWarehouseStockValue"
      />
      <el-table-column
        width="120"
        label="虚拟仓采购在途"
        align="center"
        prop="virtualWarehouseProcurementInTransit"
      />
      <el-table-column
        width="120"
        label="安全库存下限"
        align="center"
        prop="minSafeStock"
      />
      <el-table-column
        width="120"
        label="安全库存上限"
        align="center"
        prop="maxSafeStock"
      />
      <el-table-column
        width="120"
        label="安全库存天数下限"
        align="center"
        prop="minSafeDays"
      />
      <el-table-column
        width="120"
        label="安全库存天数上限"
        align="center"
        prop="maxSafeDays"
      />
      <el-table-column
        width="120"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['product:origvirtualinventory:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['product:origvirtualinventory:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改原始虚拟库存对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="虚拟仓名称" prop="virtualWarehouseName">
          <el-input
            v-model="form.virtualWarehouseName"
            placeholder="请输入虚拟仓名称"
          />
        </el-form-item>
        <el-form-item label="图" prop="imageUrl">
          <el-input
            v-model="form.imageUrl"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="商品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入商品名称" />
        </el-form-item>
        <el-form-item label="颜色规格" prop="colorSpecification">
          <el-input
            v-model="form.colorSpecification"
            placeholder="请输入颜色规格"
          />
        </el-form-item>
        <el-form-item label="商品编码" prop="sku">
          <el-input v-model="form.sku" placeholder="请输入商品编码" />
        </el-form-item>
        <el-form-item label="款式编码" prop="spu">
          <el-input v-model="form.spu" placeholder="请输入款式编码" />
        </el-form-item>
        <el-form-item label="数量" prop="quantity">
          <el-input v-model="form.quantity" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="订单占有数" prop="orderPossession">
          <el-input
            v-model="form.orderPossession"
            placeholder="请输入订单占有数"
          />
        </el-form-item>
        <el-form-item label="仓库待发数" prop="warehousePending">
          <el-input
            v-model="form.warehousePending"
            placeholder="请输入仓库待发数"
          />
        </el-form-item>
        <el-form-item label="虚拟库存数" prop="virtualStock">
          <el-input
            v-model="form.virtualStock"
            placeholder="请输入虚拟库存数"
          />
        </el-form-item>
        <el-form-item label="虚拟仓可用数" prop="virtualWarehouseAvailable">
          <el-input
            v-model="form.virtualWarehouseAvailable"
            placeholder="请输入虚拟仓可用数"
          />
        </el-form-item>
        <el-form-item label="虚拟仓可配货数" prop="virtualWarehouseAllocable">
          <el-input
            v-model="form.virtualWarehouseAllocable"
            placeholder="请输入虚拟仓可配货数"
          />
        </el-form-item>
        <el-form-item label="实际库存数" prop="actualStock">
          <el-input v-model="form.actualStock" placeholder="请输入实际库存数" />
        </el-form-item>
        <el-form-item label="公有可用数" prop="publicAvailableStock">
          <el-input
            v-model="form.publicAvailableStock"
            placeholder="请输入公有可用数"
          />
        </el-form-item>
        <el-form-item
          label="公有可用数不包含虚拟库存"
          prop="publicAvailableStockExcludingVirtual"
        >
          <el-input
            v-model="form.publicAvailableStockExcludingVirtual"
            placeholder="请输入公有可用数不包含虚拟库存"
          />
        </el-form-item>
        <el-form-item label="调拨在途数" prop="transferInTransit">
          <el-input
            v-model="form.transferInTransit"
            placeholder="请输入调拨在途数"
          />
        </el-form-item>
        <el-form-item label="进货仓库存" prop="purchaseWarehouseStock">
          <el-input
            v-model="form.purchaseWarehouseStock"
            placeholder="请输入进货仓库存"
          />
        </el-form-item>
        <el-form-item label="7天发货量" prop="sevenDayShipments">
          <el-input
            v-model="form.sevenDayShipments"
            placeholder="请输入7天发货量"
          />
        </el-form-item>
        <el-form-item label="15天发货量" prop="fifteenDayShipments">
          <el-input
            v-model="form.fifteenDayShipments"
            placeholder="请输入15天发货量"
          />
        </el-form-item>
        <el-form-item label="30天发货量" prop="thirtyDayShipments">
          <el-input
            v-model="form.thirtyDayShipments"
            placeholder="请输入30天发货量"
          />
        </el-form-item>
        <el-form-item label="7天退货量" prop="sevenDayReturns">
          <el-input
            v-model="form.sevenDayReturns"
            placeholder="请输入7天退货量"
          />
        </el-form-item>
        <el-form-item label="15天退货量" prop="fifteenDayReturns">
          <el-input
            v-model="form.fifteenDayReturns"
            placeholder="请输入15天退货量"
          />
        </el-form-item>
        <el-form-item label="30天退货量" prop="thirtyDayReturns">
          <el-input
            v-model="form.thirtyDayReturns"
            placeholder="请输入30天退货量"
          />
        </el-form-item>
        <el-form-item label="库存同步数" prop="inventorySync">
          <el-input
            v-model="form.inventorySync"
            placeholder="请输入库存同步数"
          />
        </el-form-item>
        <el-form-item label="成本" prop="cost">
          <el-input v-model="form.cost" placeholder="请输入成本" />
        </el-form-item>
        <el-form-item label="虚拟仓库存金额" prop="virtualWarehouseStockValue">
          <el-input
            v-model="form.virtualWarehouseStockValue"
            placeholder="请输入虚拟仓库存金额"
          />
        </el-form-item>
        <el-form-item
          label="虚拟仓采购在途"
          prop="virtualWarehouseProcurementInTransit"
        >
          <el-input
            v-model="form.virtualWarehouseProcurementInTransit"
            placeholder="请输入虚拟仓采购在途"
          />
        </el-form-item>
        <el-form-item label="安全库存下限" prop="minSafeStock">
          <el-input
            v-model="form.minSafeStock"
            placeholder="请输入安全库存下限"
          />
        </el-form-item>
        <el-form-item label="安全库存上限" prop="maxSafeStock">
          <el-input
            v-model="form.maxSafeStock"
            placeholder="请输入安全库存上限"
          />
        </el-form-item>
        <el-form-item label="安全库存天数下限" prop="minSafeDays">
          <el-input
            v-model="form.minSafeDays"
            placeholder="请输入安全库存天数下限"
          />
        </el-form-item>
        <el-form-item label="安全库存天数上限" prop="maxSafeDays">
          <el-input
            v-model="form.maxSafeDays"
            placeholder="请输入安全库存天数上限"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
//--------导入token
import { getToken } from "@/utils/auth";
import {
  listOrigvirtualinventory,
  getOrigvirtualinventory,
  delOrigvirtualinventory,
  addOrigvirtualinventory,
  updateOrigvirtualinventory,
} from "@/api/inventory/origvirtualinventory";

export default {
  name: "Origvirtualinventory",
  data() {
    return {
      pjtUrl: process.env.VUE_APP_BASE_API,
      fileLi: [],
      file: "",
      dialogVisible: false,
      // 图片数量限制
      limit: 2,
      Upload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url:
          process.env.VUE_APP_BASE_API +
          "/product/origvirtualinventory/importData",
      },
      isOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 原始虚拟库存表格数据
      origvirtualinventoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        virtualWarehouseName: null,
        imageUrl: null,
        productName: null,
        colorSpecification: null,
        sku: null,
        spu: null,
        status: null,
        quantity: null,
        orderPossession: null,
        warehousePending: null,
        virtualStock: null,
        virtualWarehouseAvailable: null,
        virtualWarehouseAllocable: null,
        actualStock: null,
        publicAvailableStock: null,
        publicAvailableStockExcludingVirtual: null,
        transferInTransit: null,
        purchaseWarehouseStock: null,
        sevenDayShipments: null,
        fifteenDayShipments: null,
        thirtyDayShipments: null,
        sevenDayReturns: null,
        fifteenDayReturns: null,
        thirtyDayReturns: null,
        inventorySync: null,
        cost: null,
        virtualWarehouseStockValue: null,
        virtualWarehouseProcurementInTransit: null,
        minSafeStock: null,
        maxSafeStock: null,
        minSafeDays: null,
        maxSafeDays: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询原始虚拟库存列表 */
    getList() {
      this.loading = true;
      listOrigvirtualinventory(this.queryParams).then((response) => {
        this.origvirtualinventoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        virtualWarehouseName: null,
        imageUrl: null,
        productName: null,
        colorSpecification: null,
        sku: null,
        spu: null,
        status: null,
        quantity: null,
        orderPossession: null,
        warehousePending: null,
        virtualStock: null,
        virtualWarehouseAvailable: null,
        virtualWarehouseAllocable: null,
        actualStock: null,
        publicAvailableStock: null,
        publicAvailableStockExcludingVirtual: null,
        transferInTransit: null,
        purchaseWarehouseStock: null,
        sevenDayShipments: null,
        fifteenDayShipments: null,
        thirtyDayShipments: null,
        sevenDayReturns: null,
        fifteenDayReturns: null,
        thirtyDayReturns: null,
        inventorySync: null,
        cost: null,
        virtualWarehouseStockValue: null,
        virtualWarehouseProcurementInTransit: null,
        minSafeStock: null,
        maxSafeStock: null,
        minSafeDays: null,
        maxSafeDays: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加原始虚拟库存";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getOrigvirtualinventory(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改原始虚拟库存";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateOrigvirtualinventory(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrigvirtualinventory(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除原始虚拟库存编号为"' + ids + '"的数据项？')
        .then(function () {
          return delOrigvirtualinventory(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "product/origvirtualinventory/export",
        {
          ...this.queryParams,
        },
        `origvirtualinventory_${new Date().getTime()}.xlsx`
      );
    },
    //部门文件导入修改打开
    daoru() {
      this.dialogVisible = true;
    },
    // 打开加载层
    openUploadLoading() {
      this.$modal.loading("正在导入，请稍候！");
    },
    //文件导入成功回传

    handlePictureSuccessPic(res, file) {
      this.$refs.daoru.clearFiles(); //去掉文件列表
      this.$modal.closeLoading();
      console.log(JSON.stringify(res));
      //设置图片访问路径 （url 后台传过来的的上传地址）
      // this.picUrl = file.response.url;
      // const url = file.response.fileName;
      this.file = file.response.url;
      console.log(JSON.stringify(this.file));
      if (res.code == 200) {
        this.dialogVisible = false;

        this.$modal.msgSuccess(res.msg);
        // if (res.msg == "操作成功") {
        //   this.$modal.msgSuccess("导入成功");
        // } else {
        //   this.$modal.msgError(res.msg);
        // }
        this.getList();
        // return true
      } else {
        this.$modal.msgError(res.msg);
        this.dialogVisible = true;
        // this.$message.msgError('该颜色未在字典定义')
        return;
      }
    },
    //图片预览
    handlePictureCardPreview(file) {
      // this.picUrl = file.url
      // this.imageUrl = file.url;
      // this.dialogVisible = true;
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type == 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 100MB!");
      }
      this.openUploadLoading();
      return isLt2M;
    },

    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传链接文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传文件让第二次覆盖第一的文件
    changeFile1(file, fileList) {
      if (fileList.length > 1) {
        this.fileLi = fileList.slice(-1);

        // this.fileList = [fileList[fileList.length - 1]]//这一步，是 展示最后一次选择文件
      }
      // this.fileSpecial = fileList;
    },
  },
};
</script>
